#include <REGX52.H>

void delay(unsigned int xms)		//@12.000MHz
{
	unsigned char i, j;

	while(xms)
	{
		i = 2;
		j = 239;
		do
		{
			while (--j);
		} while (--i);
		xms--;
	}
}


void main()
{
	unsigned char count = 0;
	
	P2 = ~0X01;
	while(1)
	{
		if(P3_1 == 0)
		{
			delay(20);
			while(P3_1 == 0);
			delay(20);
			
			count++;
			if(count >= 8)
			{
				count = 0;
			}
			P2 = ~(0x01<<count);
		}
		
		if(P3_0 == 0)
		{
			delay(20);
			while(P3_0 == 0);
			delay(20);

			if(count == 0)
			{
				count = 7;
			}
			else
			{			
				count--;
			}
			P2 = ~(0x01<<count);
		}
	}
}
